using ASP;
using System;
using System.Collections.Generic;
using System.IO;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
public class AjaxPage_Reviews : Page, IRequiresSessionState
{
	private class Review
	{
		private string ip;
		private string date;
		private string content;
		public string IP
		{
			get
			{
				return this.ip;
			}
			set
			{
				this.ip = value;
			}
		}
		public string Date
		{
			get
			{
				return this.date;
			}
			set
			{
				this.date = value;
			}
		}
		public string Content
		{
			get
			{
				return this.content;
			}
			set
			{
				this.content = value;
			}
		}
		public Review()
		{
			this.ip = (this.date = (this.content = string.Empty));
		}
	}
	protected Literal txtStatus;
	protected Repeater rpView;
	protected int Count = 0;
	protected int Filter = 1;
	protected int pageIndex = 0;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		string text = base.Request.Form["Method"];
		if (text != null && text.Length >= 1)
		{
			string text2 = base.Server.MapPath("../..") + "/App_Data/ReviewForVedio.xml";
			if (!File.Exists(text2))
			{
				File.WriteAllText(text2, "<?xml version=\"1.0\" encoding=\"utf-8\" ?><Review></Review>");
			}
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.Load(text2);
			if (text.Equals("list"))
			{
				this.pageIndex = Convert.ToInt32(base.Request.Form["PageIndex"]);
				int num = 10;
				XmlNodeList xmlNodeList = xmlDocument.SelectNodes("Review/review[@id='" + base.Request.Form["Id"] + "']");
				int num2 = this.Count = xmlNodeList.Count;
				if (num * (this.pageIndex + 1) <= this.Count - 1)
				{
					num2 = num * (this.pageIndex + 1);
				}
				this.Filter = this.Count / num;
				if (this.Filter * num < this.Count)
				{
					this.Filter++;
				}
				List<AjaxPage_Reviews.Review> list = new List<AjaxPage_Reviews.Review>();
				for (int i = this.pageIndex * num; i < num2; i++)
				{
					AjaxPage_Reviews.Review review = new AjaxPage_Reviews.Review();
					XmlAttributeCollection attributes = xmlNodeList[i].Attributes;
					review.IP = attributes[1].Value;
					review.Date = attributes[2].Value;
					review.Content = attributes[3].Value;
					list.Add(review);
				}
				this.rpView.DataSource = list;
				this.rpView.DataBind();
				list.Clear();
			}
			else
			{
				if (text.Equals("add"))
				{
					string text3 = base.Request.Form["Id"];
					if (text3.Length > 0)
					{
						XmlElement xmlElement = xmlDocument.CreateElement("review");
						XmlAttribute xmlAttribute = xmlDocument.CreateAttribute("id");
						xmlAttribute.Value = text3;
						xmlElement.Attributes.Append(xmlAttribute);
						xmlAttribute = xmlDocument.CreateAttribute("ip");
						xmlAttribute.Value = base.Request.UserHostAddress;
						xmlElement.Attributes.Append(xmlAttribute);
						xmlAttribute = xmlDocument.CreateAttribute("date");
						xmlAttribute.Value = DateTime.Now.ToString("yyyy/M/dd hh:mm:ss");
						xmlElement.Attributes.Append(xmlAttribute);
						xmlAttribute = xmlDocument.CreateAttribute("content");
						xmlAttribute.Value = base.Request.Form["Content"];
						xmlElement.Attributes.Append(xmlAttribute);
						if (xmlDocument.DocumentElement.ChildNodes.Count == 0)
						{
							xmlDocument.DocumentElement.AppendChild(xmlElement);
						}
						else
						{
							xmlDocument.DocumentElement.InsertBefore(xmlElement, xmlDocument.DocumentElement.FirstChild);
						}
						xmlDocument.Save(text2);
						this.txtStatus.Text = "success";
					}
					else
					{
						this.txtStatus.Text = "不存在此视频";
					}
				}
			}
		}
	}
}
